<!--
 * Description: CBOM基础数据
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/04/14 02:52
-->

<template>
  <div style="height:100%">
    <!-- 查询条件 -->
    <BaseFunc
      :is-requesting="isRequesting"
      :query-form="queryForm"
      :visible.sync="advanceOptionDrawer"
      @query="query"
    >
      <!--抽屉内部查询表单-->
      <template>
        <el-form class="g-advance-drawer-form" label-width="100px" :model="queryForm" size="medium">
          <el-row>
            <!--BU-->
            <el-col :span="6">
              <el-form-item :label="$t('Cbom.bu')">
                <el-input v-model="queryForm.bu" clearable />
              </el-form-item>
            </el-col>
            <!--产品专案-->
            <el-col :span="6">
              <el-form-item :label="$t('Cbom.project')">
                <el-input v-model="queryForm.project" clearable />
              </el-form-item>
            </el-col>

            <!--Subject-->
            <el-col :span="6">
              <el-form-item label="Subject">
                <el-input v-model="queryForm.subject" clearable />
              </el-form-item>
            </el-col>

            <!--Tracking Sku-->
            <el-col :span="6">
              <el-form-item :label="$t('Cbom.trackingSku')">
                <el-input v-model="queryForm.trackingSku" clearable />
              </el-form-item>
            </el-col>
            <!--创建人-->
            <el-col :span="6">
              <el-form-item :label="$t('Cbom.createUser')">
                <el-select
                  v-model="queryForm.createUser"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!--修改人-->
            <el-col :span="6">
              <el-form-item :label="$t('Cbom.modifyUser')">
                <el-select
                  v-model="queryForm.modifyUser"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
    </BaseFunc>

    <!--数据表格-->
    <BaseTable
      :is-requesting="isRequesting"
      :page-number.sync="pageNumber"
      :page-size.sync="pageSize"
      :table-data="tableData"
      :total="total"
      @query="query"
    >
      <template slot="header">
        <!--序号列-->
        <el-table-column align="center" fixed :label="$t('table.NO')" min-width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
      </template>

      <template>
        <!--bu类型-->
        <el-table-column
          align="center"
          :label="$t('Cbom.bu')"
          min-width="200px"
          prop="bu"
          sortable
        />
        <!--产品专案-->
        <el-table-column
          align="center"
          :label="$t('Cbom.project')"
          min-width="200px"
          prop="project"
          sortable
        />

        <!--Subject-->
        <el-table-column align="center" label="Subject" min-width="200px" prop="subject" sortable />

        <!--Tracking Sku-->
        <el-table-column
          align="center"
          :label="$t('Cbom.trackingSku')"
          min-width="200px"
          prop="trackingSku"
          sortable
        />

        <!--创建人-->
        <el-table-column align="center" :label="$t('Cbom.createUser')" min-width="200px" sortable>
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.createUser) }}</span>
          </template>
        </el-table-column>

        <!--创建时间-->
        <el-table-column
          align="center"
          :label="$t('Cbom.createTime')"
          min-width="200px"
          prop="createTime"
          sortable
        />

        <!--修改人-->
        <el-table-column align="center" :label="$t('Cbom.modifyUser')" min-width="200px" sortable>
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.modifyUser) }}</span>
          </template>
        </el-table-column>

        <!--修改时间-->
        <el-table-column
          align="center"
          :label="$t('Cbom.modifyTime')"
          min-width="200px"
          prop="modifyTime"
          sortable
        />
      </template>

      <!-- 右浮动 -->
      <template slot="end">
        <!--操作列-->
        <el-table-column
          align="center"
          fixed="right"
          :label="$t('table.operate')"
          min-width="120px"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPer('view')"
              size="mini"
              type="text"
              @click="rowView(scope.$index, scope.row)"
            >
              <i class="el-icon-view el-icon--right"></i>
              {{ $t('button.view') }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </BaseTable>
  </div>
</template>
<script>
import { cbomReportPageList } from '@/api/cbom/report'
export default {
  name: 'CbomReportBaseData',
  data() {
    return {
      // 正在查询
      isRequesting: false,
      // 高级查询选项抽屉弹出标识
      advanceOptionDrawer: false,
      // 页码
      pageNumber: 1,
      // 页展示行数
      pageSize: 10,
      // 总行数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询表单对象
      queryForm: {},
      // 正在刷新的行的标识
      refreshRowIdList: []
    }
  },
  created() {
    this.pageDataInit()
    /** 刷新数据 */
    this.$bus.$on('cbom-reload', () => {
      this.pageDataInit()
    })
  },
  beforeDestroy() {
    /** 刷新数据 */
    this.$bus.$off('cbom-reload')
  },
  methods: {
    /* 页面数据初始化*/
    pageDataInit() {
      this.query()
    },
    /* 查询表格数据*/
    async query() {
      try {
        this.isRequesting = true
        this.advanceOptionDrawer = false
        const res = await cbomReportPageList({
          pageSize: this.pageSize,
          pageNumber: this.pageNumber,
          pageCondition: this.queryForm
        })
        this.tableData = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },

    // 行查看
    rowView(index, rowData) {
      this.$bus.$emit('cbom-detail-view', index, rowData)
    }
  }
}
</script>
